<?php

namespace App\Admin\Controllers;

use App\Services\AqConversationDetailService;
use App\Support\TableAqViewComponents;
use Slowlyo\OwlAdmin\Controllers\AdminController;

/**
 * 问答数据
 *
 * @property AqConversationDetailService $service
 */
class AqConversationDetailController extends AdminController
{
	protected string $serviceName = AqConversationDetailService::class;

	public function list()
	{
		$crud = $this->baseCRUD()
			->filter($this->baseFilter()->body([
				amis()->TextControl('username', '用户名')->size('md')->clearable(1),
				amis()->TextControl('request_text', '问题')->size('md')->clearable(1),
				amis()->TextControl('response_text', '回复')->size('md')->clearable(1),
				amis()->TextControl('request_id', 'ID')->size('md')->clearable(1),
				amis()->NumberControl('score', '评分')->min(0)->max(5)->size('md')->clearable(1),
			]))
			->filterTogglable(false)
			->headerToolbar([
				...$this->baseHeaderToolBar()
			])
			->bulkActions([])
			->columns([
				amis()->Operation()->label('问题')->buttons([
					amis()->Html()->label('信息')->tpl('<p><a href="https://xqnmz.com/home.php?mod=space&uid=${conversation.uid}">${conversation.user.username}</a><br />模型：${request_data.model}<br />时间：${created_at}<br />ID：${request_id}<br />评分：${score}分</p>'),
					amis()->Tag()->label('有图')->color('success')->displayMode('status')->visibleOn('${images.length}'),
					amis()->Tag()->label('有文档')->color('processing')->displayMode('status')->visibleOn('${docs}'),
				])->width(260),
				amis()->Html()->tpl('<textarea rows="7" style="width: 100%; padding:8px; border: 1px solid #ddd; resize: none">${request_text}</textarea>')->width(300),
				amis()->Html()->label('回复')->tpl('<textarea rows="7" style="width: 100%; padding:8px; border: 1px solid #ddd; resize: none">${response_text}</textarea>'),
				amis()->Operation()->label('操作')->buttons([
					TableAqViewComponents::make()->rowShowButton()
				])->width(60),
				//amis()->Images()->label('图片')->displayMode('thumb')->source('${images}')->enlargeAble('1')->width(400),
				//amis()->Html()->label('文档')->tpl('<a href="${docs.filepath}">下载文档</a>')->width(100),
			]);

		return $this->baseList($crud);
	}

	public function form($isEdit = false)
	{
		return $this->baseForm()->body([
			amis()->TextControl('conversation_id', 'ConversationId'),
			amis()->TextControl('request_text', 'RequestText'),
			amis()->TextControl('response_text', 'ResponseText'),
			amis()->TextControl('request_id', 'RequestId'),
			amis()->TextControl('request_data', 'RequestData'),
			amis()->TextControl('response_data', 'ResponseData'),
			amis()->TextControl('score', 'Score'),
		]);
	}

	public function detail()
	{
		return $this->baseDetail()->body([
			amis()->TextControl('id', 'ID')->static(),
			amis()->TextControl('conversation_id', 'ConversationId')->static(),
			amis()->TextControl('request_text', 'RequestText')->static(),
			amis()->TextControl('response_text', 'ResponseText')->static(),
			amis()->TextControl('request_id', 'RequestId')->static(),
			amis()->TextControl('request_data', 'RequestData')->static(),
			amis()->TextControl('response_data', 'ResponseData')->static(),
			amis()->TextControl('score', 'Score')->static(),
			amis()->TextControl('created_at', admin_trans('admin.created_at'))->static(),
			amis()->TextControl('updated_at', admin_trans('admin.updated_at'))->static(),
		]);
	}

	public function getCount()
	{
		return $this->service->getCount();
	}
}
